-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[doc] Usecases with docbase as param #1502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] Usecases with docbase as param #1502
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good, but I would like to see better decoupling between core compiler and dottydoc.
|
||
class ExpansionLimitExceeded(str: String) extends Exception | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why put this in core instead of dottydoc? A lot of the logic seems to be doc-specific. Proposal: Keep Comment as a pure data class as it was in Scanners. Implement the new logic as methods external to Comment. Comment contains only defs (the only val in it could as well be a def), so this is easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky: I think the basis of this review rests on the thoughts in this comment, as such let me try to address these concerns here in summary.
My reasons for keeping this in the compiler is for tooling - I think that's the same reason as to why this implementation was in nsc
and not in Scaladoc for scalac.
When we have a presentation compiler - we're going to want expanded (or "cooked") comments for the standard library entities.
The Comment
in core
as such - does not deal with things that dottydoc does - like @group
and other dottydoc specific annotations - it only deals with expansion of definitions and the comment inheritance.
@@ -68,6 +69,9 @@ object Contexts { | |||
/** The context base at the root */ | |||
val base: ContextBase | |||
|
|||
/** Documentation base */ | |||
def getDocbase = property(DocContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this out of Context? The design should be ideally one of a plugin. That is, there is a context property, but the Contexts
object knows nothing about it. I would do it more like we model defn
: Put in the main Doc object:
val DocBase = ...
def getDocBase(implicit ctx: Context) = ctx.property(DocBase)
@@ -573,10 +578,15 @@ object Contexts { | |||
} | |||
} | |||
|
|||
val DocContext = new Key[DocBase] | |||
class DocBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DocContext should be renamed to DocBase for consistency.
Both kinds of DocBase should also move to the dottydoc package, I think.
@@ -1515,7 +1515,9 @@ object SymDenotations { | |||
|
|||
/** Enter a symbol in given `scope` without potentially replacing the old copy. */ | |||
def enterNoReplace(sym: Symbol, scope: MutableScope)(implicit ctx: Context): Unit = { | |||
require((sym.denot.flagsUNSAFE is Private) || !(this is Frozen) || (scope ne this.unforcedDecls) || sym.hasAnnotation(defn.ScalaStaticAnnot)) | |||
def isUsecase = ctx.property(DocContext).isDefined && sym.name.show.takeRight(4) == "$doc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this line to a "isUserCase" method in the dottydoc package.
@@ -1456,6 +1462,45 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |||
traverse(stats) | |||
} | |||
|
|||
private def typedUsecases(syms: List[Symbol], owner: Symbol)(implicit ctx: Context): Unit = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think expandParentDocs belongs in DottyDoc, not in Typer. So I would move typedUseCases there as well. Pass the typer as a paremeter, so it can call back to enterSymbol, createSymbol, typedStats.
import scala.reflect.internal.Chars._ | ||
|
||
object CommentUtils { | ||
object CommentParsing { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment what it does.
Also what's the motivation for keeping this in util
? Is it used outside dottydoc as well?
e4e19e0
to
b3d2b2c
Compare
doc.map(d => _docstrings += (sym -> d)) | ||
} | ||
|
||
abstract case class Comment(pos: Position, raw: String)(implicit ctx: Context) { self => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing a context into a class always poses the risk of space leaks. It's better not to make the context implicit, so that we can track precisely where it is used. It's even better not to pass a context into a class at all.
b3d2b2c
to
86c9209
Compare
LGTM! |
Also eliminates the need for comment processing to be part of the `DocASTPhase`, so this should be put into a DocMiniPhase
86c9209
to
9bcf282
Compare
Fixes scala#1502 by making the length field use 1 or 2 bytes, depending on the number of parameters in a signature.
Fixes scala#1502 by making the length field use 1 or 2 bytes, depending on the number of parameters in a signature.
Cherry-picked the commit from @odersky's branch on inline that refactors
Attachment.Key[A]
=>Property.Key[A]
and implemented the docbase as a property - which will then cause the typechecking of usecases only when the docbase property is present in the context.Other than that, not much has changed from #1472
Review: @odersky